/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BuscarFacturaFrame.java
 *
 * Created on Oct 27, 2011, 1:53:24 PM
 */
package com.imptec.reportfly.view;

import com.imptec.reportfly.Util.CrearConexiones;
import com.imptec.reportfly.Util.Fechas;
import com.imptec.reportfly.model.Cliente;
import com.imptec.reportfly.report.ReporteCuentaCorrientePendiente;
import com.imptec.reportfly.report.ReportePromocion;
import com.imptec.reportfly.service.ClienteServiceImpl;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openswing.swing.mdi.client.InternalFrame;

/**
 *
 * @author POTENTE
 */
public class ReporteDeCCPendientesPorFacturarFrame extends InternalFrame {

    /** Creates new form BuscarFacturaFrame */
     private ReporteCuentaCorrientePendiente jasper;
     private Connection con;
     ArrayList<Cliente> lista;
    public ReporteDeCCPendientesPorFacturarFrame() {
        try {
            initComponents();
            rbtnFechaNegocio.setSelected(true);
            cargar();
            this.setResizable(false);
            jasper=new ReporteCuentaCorrientePendiente();
        } catch (Exception ex) {
            Logger.getLogger(ReporteDeCCPendientesPorFacturarFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void cargar(){  
        con=new CrearConexiones().abrir();
        ClienteServiceImpl serv=new ClienteServiceImpl();
        lista= serv.obtenerLista(con);
        for (Cliente cliente : lista) {          
            jcombo.addItem(cliente.getNombre());        
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        labelControl1 = new org.openswing.swing.client.LabelControl();
        labelControl4 = new org.openswing.swing.client.LabelControl();
        labelControl5 = new org.openswing.swing.client.LabelControl();
        btnGenerarReporte = new javax.swing.JButton();
        rbtnFechaNegocio = new org.openswing.swing.client.RadioButtonControl();
        rbtnFechaReal = new org.openswing.swing.client.RadioButtonControl();
        jcombo = new javax.swing.JComboBox();
        txtFechaInicial = new com.toedter.calendar.JDateChooser();
        txtFechaFinal = new com.toedter.calendar.JDateChooser();

        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Fecha de Negocio", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 51, 51))); // NOI18N
        jPanel1.setLayout(null);

        labelControl1.setText("Cliente:");
        jPanel1.add(labelControl1);
        labelControl1.setBounds(20, 40, 40, 14);

        labelControl4.setText("Fecha Inicial :");
        jPanel1.add(labelControl4);
        labelControl4.setBounds(130, 120, 66, 14);

        labelControl5.setText("Fecha Final :");
        jPanel1.add(labelControl5);
        labelControl5.setBounds(130, 160, 63, 14);

        btnGenerarReporte.setText("Generar Reporte");
        btnGenerarReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerarReporteActionPerformed(evt);
            }
        });
        jPanel1.add(btnGenerarReporte);
        btnGenerarReporte.setBounds(310, 200, 120, 23);

        buttonGroup1.add(rbtnFechaNegocio);
        rbtnFechaNegocio.setText("Fecha de Negocio");
        rbtnFechaNegocio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnFechaNegocioActionPerformed(evt);
            }
        });
        jPanel1.add(rbtnFechaNegocio);
        rbtnFechaNegocio.setBounds(80, 80, 111, 23);

        buttonGroup1.add(rbtnFechaReal);
        rbtnFechaReal.setText("Fecha Real");
        jPanel1.add(rbtnFechaReal);
        rbtnFechaReal.setBounds(250, 80, 123, 23);

        jPanel1.add(jcombo);
        jcombo.setBounds(60, 40, 380, 20);

        txtFechaInicial.setDateFormatString("dd-MM-yyyy");
        jPanel1.add(txtFechaInicial);
        txtFechaInicial.setBounds(210, 120, 130, 20);

        txtFechaFinal.setDateFormatString("dd-MM-yyyy"); // NOI18N
        jPanel1.add(txtFechaFinal);
        txtFechaFinal.setBounds(210, 160, 130, 20);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(20, 10, 450, 240);
    }// </editor-fold>//GEN-END:initComponents

private void btnGenerarReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerarReporteActionPerformed
// TODO add your handling code here:
    
    String ti="";
    Fechas fecha=new Fechas();
    String fi = fecha.getFechaDDMMYYYY(txtFechaInicial.getDate());
    String ff = fecha.getFechaDDMMYYYY(txtFechaFinal.getDate());
    String cli = (String) jcombo.getSelectedItem();
    for (Cliente cliente : lista) {
        if(cli==cliente.getNombre()) cli = cliente.getCodigo();
    }
    System.out.println(cli);
    if(rbtnFechaNegocio.isSelected()) ti="negocio";
    if(rbtnFechaReal.isSelected()) ti="real";
    jasper.runReporte(fi,ff,cli,ti);
}//GEN-LAST:event_btnGenerarReporteActionPerformed

private void rbtnFechaNegocioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnFechaNegocioActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_rbtnFechaNegocioActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGenerarReporte;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox jcombo;
    private org.openswing.swing.client.LabelControl labelControl1;
    private org.openswing.swing.client.LabelControl labelControl4;
    private org.openswing.swing.client.LabelControl labelControl5;
    private org.openswing.swing.client.RadioButtonControl rbtnFechaNegocio;
    private org.openswing.swing.client.RadioButtonControl rbtnFechaReal;
    private com.toedter.calendar.JDateChooser txtFechaFinal;
    private com.toedter.calendar.JDateChooser txtFechaInicial;
    // End of variables declaration//GEN-END:variables
}
